main.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import {
  2. _decorator,
  3. Component,
  4. EPhysics2DDrawFlags,
  5. EventKeyboard,
  6. input,
  7. Input,
  8. KeyCode,
  9. Label,
  10. Node,
  11. PhysicsSystem2D,
  12. sys,
  13. screen,
  14. director,
  15. View,
  16. ResolutionPolicy,
  17. JsonAsset,
  18. resources,
  19. AudioClip,
  20. AudioSource,
  21. Camera,
  22. } from 'cc';
  23. import { CheckButton } from './CheckButton';
  24. import { UsefulTools } from '../curvetexture/UsefulTools';
  25. const { ccclass, property } = _decorator;
  26. @ccclass('main')
  27. export class main extends Component {
  28. // @property({ type: CheckButton })
  29. // checkButton1: CheckButton | null = null;
  30. @property({ type: CheckButton })
  31. checkButton2: CheckButton | null = null;
  32. @property({ type: CheckButton })
  33. checkButton3: CheckButton | null = null;
  34. // @property({ type: Label })
  35. // label: Label | null = null;
  36. @property({ type: Camera })
  37. camera: Camera | null = null;
  38. protected onLoad(): void {
  39. // console.log(`main onLoad`);
  40. this.node.layer = UsefulTools.checkAndAddLayerByName('PERSISIT');
  41. this.node.walk((node: Node) => {
  42. node.layer = UsefulTools.checkAndAddLayerByName('PERSISIT');
  43. });
  44. if (this.camera) {
  45. this.camera.visibility = UsefulTools.checkAndAddLayerByName('PERSISIT');
  46. }
  47. }
  48. protected async onEnable() {
  49. if (!director.isPersistRootNode(this.node)) {
  50. director.addPersistRootNode(this.node);
  51. }
  52. // let checkMoveTouch = (child: Node) => {
  53. // if (child.name.startsWith('gizmo_')) {
  54. // let c = child.getComponent(MoveWithTouch);
  55. // if (!c) {
  56. // c = child.addComponent(MoveWithTouch);
  57. // }
  58. // }
  59. // };
  60. // let cts = this.node.getComponentsInChildren(CurveTexture);
  61. // cts.forEach((ct) => {
  62. // ct.node.children.forEach((child) => {
  63. // checkMoveTouch(child);
  64. // });
  65. // });
  66. // this.checkButton1.bindFunction((from: CheckButton) => {
  67. // cts.forEach((ct) => {
  68. // ct.editWhenRun = from.onoff;
  69. // if (ct.editWhenRun) {
  70. // //等这一帧控制节点生成后再设置
  71. // this.scheduleOnce(() => {
  72. // cts.forEach((ct) => {
  73. // ct.node.children.forEach((child) => {
  74. // checkMoveTouch(child);
  75. // });
  76. // });
  77. // }, 1 / 60);
  78. // }
  79. // });
  80. // });
  81. this.checkButton2.bindFunction((from: CheckButton) => {
  82. //不能在EPhysics2DDrawFlags.None和其他值之间切换,引擎代码健壮性不够,会报错
  83. PhysicsSystem2D.instance.debugDrawFlags = from.onoff ? EPhysics2DDrawFlags.Shape : EPhysics2DDrawFlags.Controller;
  84. });
  85. this.checkButton3.bindFunction((from: CheckButton) => {
  86. director.loadScene('scene_START');
  87. });
  88. // input.on(Input.EventType.KEY_DOWN, (event: EventKeyboard) => {
  89. // if (event.keyCode === KeyCode.KEY_I) {
  90. // // this.node_ct.getComponent(CurveTexture)!.debugPrint();
  91. // // this.node_ct2.getComponent(CurveTexture)!.debugPrint();
  92. // }
  93. // });
  94. // if (sys.language !== 'zh') {
  95. // this.label.string = `1: Need to enable feature cropping => 3D => 3D base features
  96. // 2: Need to enable preferences => Lab => Keep the scenario main loop running
  97. // 3: A physical property is a PolygonCollider2D component added on a child node of a specific name
  98. // `;
  99. // } else {
  100. // this.label.string = `1:需要开启 功能裁剪 => 3D => 3D基础功能
  101. // 2:需要开启 偏好设置 => 实验室 => 保持场景主循环运行
  102. // 3:物理属性是在子节点上添加的 PolygonCollider2D 组件`;
  103. // }
  104. }
  105. start() {}
  106. update(deltaTime: number) {}
  107. }